package demo4;

abstract class Animal {
    public String name;
    public int age;

    public abstract void eat();

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

interface IFly {
    void fly();
}

interface IRun {
    void run();
}

interface ISwim {
    void swim();
}

class Dog extends Animal implements IRun {
    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + "正在吃狗粮");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用四条腿跑跑");
    }
}

class Frog extends Animal implements IRun, ISwim {
    public Frog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + "正在吃蛙粮");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用两个腿跳着跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在蛙泳");
    }
}

class Duck extends Animal implements IRun, IFly, ISwim {

    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + "正在吃鸭粮");
    }

    @Override
    public void fly() {
        System.out.println(this.name + "正在飞");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用两个脚着跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在用两只脚滑着游泳");
    }
}

class Roboot implements IRun {

    @Override
    public void run() {
        System.out.println("机器人用两个脚在跑");
    }
}

public class Test {
    public static void func1(Animal animal) {
        animal.eat();
    }

    public static void running(IRun iRun) {
        iRun.run();
    }

    public static void flying(IFly iFly) {
        iFly.fly();
    }

    public static void swimming(ISwim iSwim) {
        iSwim.swim();
    }

    public static void main(String[] args) {
        running(new Duck("唐老鸭", 1));
        running(new Dog("二哈", 2));
        running(new Frog("青蛙", 3));
        running(new Roboot());

        System.out.println("-------------------------");
        flying(new Duck("唐老鸭", 1));
        System.out.println("-------------------------");
        //flying(new Dog("二哈", 2));
        swimming(new Duck("唐老鸭", 1));
        swimming(new Frog("青蛙", 3));
    }

    public static void main1(String[] args) {
        func1(new Duck("唐老鸭", 1));
        func1(new Dog("二哈", 2));
        func1(new Frog("青蛙", 3));
    }
}
